package com.bps.zzant.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Table(name = "zzant_orders")

public class OrderGarment implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5044865720392554215L;

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "orders_id", unique = true, nullable = false)
	private int orderId;
	
	@Column(name = "cus_id", unique = false, nullable = true)
	private int customerId;
	
	@Column(name = "customers_city")
	@NotEmpty(message = "The City must not be blank.")
	private String city;
	
	@Column(name = "customers_country")
	private String customersCountry;
	
	@Column(name = "customers_email_address")
	private String email;
	
	@Column(name = "customers_name")
	private String customerName;
	
	@Column(name = "customers_postcode")
	private String zip;

	@Column(name = "customers_state")
	private String state;
	
	@Column(name = "customers_street_address1")
	private String address1;
	
	@Column(name = "customers_street_address2")
	private String address2;
	
	@Column(name = "customers_telephone")
	private String tel;
	
	@Column(name = "date_purchased")
	@DateTimeFormat(pattern="MM/dd/YYYY")
	private Date datePurchased;
	
	@Column(name = "delivery_city")
	private String shipCity;
	
	@Column(name = "delivery_postcode")
	private String shipZip;
	
	@Column(name = "delivery_state")
	private String shipState;
	
	@Column(name = "delivery_street_address1")
	private String shipAddress1;
	
	@Column(name = "delivery_street_address2")
	private String ShipAddress2;
	
	@Column(name = "est_pickup_date")
	@DateTimeFormat(pattern="MM/dd/YYYY")
	private Date estPickupDate;
	
	@Column(name = "last_modified")
	@DateTimeFormat(pattern="MM/dd/YYYY")
	private Date lastModified;
	
	@Column(name = "orders_date_finished")
	@DateTimeFormat(pattern="MM/dd/YYYY")
	private Date ordersDateFinished;
	
	@Column(name = "orders_date_pickup")
	@DateTimeFormat(pattern="MM/dd/YYYY")
	private Date ordersDatePickup;
	
	@Column(name = "orders_number")
	private String ordersNumber;
	
	@Column(name = "orders_status")
	private String ordersStatus;
	
	@Column(name = "contact")
	private String contact;
	
	@Column(name = "customers_fax")
	private String fax;

	@Column(name = "customers_cell")
	private String cell;
	
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "order",cascade=CascadeType.ALL,orphanRemoval=true)
	@JsonIgnore
	private List<OrderGarmentItem> garmentItems = new ArrayList<OrderGarmentItem>(0);

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "order",cascade=CascadeType.ALL,orphanRemoval=true)
	@JsonIgnore
	private List<Payment> payments = new ArrayList<Payment>(0);
	
	public List<Payment> getPayments() {
		return payments;
	}

	public void setPayments(List<Payment> payments) {
		this.payments = payments;
	}

	public int getOrderId() {
		return orderId;
	}

	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

	public int getCustomerId() {
		return customerId;
	}

	public void setCustomerId(int customerId) {
		this.customerId = customerId;
	}



	public String getCustomersCountry() {
		return customersCountry;
	}

	public void setCustomersCountry(String customersCountry) {
		this.customersCountry = customersCountry;
	}

	public Date getDatePurchased() {
		return datePurchased;
	}

	public void setDatePurchased(Date datePurchased) {
		this.datePurchased = datePurchased;
	}

	public String getShipCity() {
		return shipCity;
	}

	public void setShipCity(String shipCity) {
		this.shipCity = shipCity;
	}

	public Date getEstPickupDate() {
		return estPickupDate;
	}

	public void setEstPickupDate(Date estPickupDate) {
		this.estPickupDate = estPickupDate;
	}

	public Date getLastModified() {
		return lastModified;
	}

	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}

	public Date getOrdersDateFinished() {
		return ordersDateFinished;
	}

	public void setOrdersDateFinished(Date ordersDateFinished) {
		this.ordersDateFinished = ordersDateFinished;
	}

	public Date getOrdersDatePickup() {
		return ordersDatePickup;
	}

	public void setOrdersDatePickup(Date ordersDatePickup) {
		this.ordersDatePickup = ordersDatePickup;
	}

	public String getOrdersNumber() {
		return ordersNumber;
	}

	public void setOrdersNumber(String ordersNumber) {
		this.ordersNumber = ordersNumber;
	}

	public String getOrdersStatus() {
		return ordersStatus;
	}

	public void setOrdersStatus(String ordersStatus) {
		this.ordersStatus = ordersStatus;
	}

	public List<OrderGarmentItem> getGarmentItems() {
		return garmentItems;
	}

	public void setGarmentItems(List<OrderGarmentItem> garmentItems) {
		this.garmentItems = garmentItems;
	}

	public String toString(){
		return "[OrderGarment]customerName="+getCustomerName()+"|address1="+getAddress1()+"|address2="+getAddress2()+"|city="+getCity()+"|state="+getState()+"|zip="+getZip()+"|telephone="+getTel()+"|email="+getEmail()+"|fax="+getFax()+"|cell="+getCell()+"|shipping 1="+getShipAddress1()+"|shipping 2="+getShipAddress2()+"|ship city="+getShipCity()+"|ship State="+getShipState()+"ship zip="+getShipZip();
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getAddress1() {
		return address1;
	}

	public void setAddress1(String address1) {
		this.address1 = address1;
	}

	public String getAddress2() {
		return address2;
	}

	public void setAddress2(String address2) {
		this.address2 = address2;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getShipZip() {
		return shipZip;
	}

	public void setShipZip(String shipZip) {
		this.shipZip = shipZip;
	}

	public String getShipState() {
		return shipState;
	}

	public void setShipState(String shipState) {
		this.shipState = shipState;
	}

	public String getShipAddress1() {
		return shipAddress1;
	}

	public void setShipAddress1(String shipAddress1) {
		this.shipAddress1 = shipAddress1;
	}

	public String getShipAddress2() {
		return ShipAddress2;
	}

	public void setShipAddress2(String shipAddress2) {
		ShipAddress2 = shipAddress2;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getCell() {
		return cell;
	}

	public void setCell(String cell) {
		this.cell = cell;
	}

	public OrderGarment(OrderForm orderForm) {
		this.orderId = orderForm.getOrderId();
		this.customerId = orderForm.getCustomerId();
		this.city = orderForm.getCity();
		this.customersCountry = orderForm.getCustomersCountry();
		this.email = orderForm.getEmail();
		this.customerName = orderForm.getCustomerName();
		this.zip = orderForm.getZip();
		this.state = orderForm.getState();
		this.address1 = orderForm.getAddress1();
		this.address2 = orderForm.getAddress2();
		this.tel = orderForm.getTel();
		this.shipCity = orderForm.getShipCity();
		this.shipZip = orderForm.getShipZip();
		this.shipState = orderForm.getShipState();
		this.shipAddress1 = orderForm.getShipAddress1();
		this.ShipAddress2 = orderForm.getShipAddress2();
		this.estPickupDate = orderForm.getEstPickupDate();	
		this.contact = orderForm.getContact();
		this.fax =orderForm.getFax();
		this.cell = orderForm.getCell();
				
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm aaa");
		sdf.setLenient(false);
		ParsePosition p = new ParsePosition( 0 );
		this.datePurchased = sdf.parse(orderForm.getDatePurchased(),p);		
		
		// this.datePurchased = orderForm.getDatePurchased();
	}

	public OrderGarment() {
		super();
	}
	
	
	
}
